<?php
namespace qiuzhizhe\Controller;
use Common\Common\Model;
use Common\Model\jobhunterModel;
use Common\Model\jobhunterObject;
use Common\Model\companyModel;
use Common\Model\companyObject;
use Common\Model\deliveryModel;
use Common\Model\deliveryObject;
use Common\Model\recruitModel;
use Common\Model\recruitObject;
use Common\Model\resumeModel;
use Common\Model\resumeObject;
use Think\Controller;
class QiantaiController extends Controller {

//    public function fuck() {
//        $id = I('get.id');
//        $data['name'] = 'xiaosi';
//        $data['age'] = 1;
//        $user = D('User')->getUserNameById($id);
//
//        dump($user, $id);
//        $this->assign($data);
//        $this->display();
//    }
    /**
     * 用户登录处理
     */
    public function login_action(){
        /** @var jobhunterModel $jobhunterFactory */
        $jobhunterFactory = D('jobhunter');
        /** @var jobhunterObject $jobhunter */
        $jobhunter = $jobhunterFactory->fetchByUsername($_POST['username']);
        if($jobhunter == null)
            $this->error('用户不存在！');
        if(!$jobhunter->checkPassword($_POST['psw']))
            $this->error('密码不正确！');
        $jobhunterFactory->login($jobhunter);
        $this->success('登录成功！', '/Qiantai/index');
    }
    /**
     * 用户注册处理
     */
    public function register_action(){
        $Dao = M("jobhunter");	// 实例化模型类
        // 构建写入的数据数组
        $data["username"] = $_POST['username'];
        $data["passwords"] = $_POST['psw'];
        $db=$Dao->where()->select();
        foreach ($db as $value){
            if($data["username"]==$value['username']){
                $i=1;
            }
        }
        if($i==1){
            $this->success('用户名存在！', '/Qiantai/register');
        }
        else{
            if($lastInsId = $Dao->add($data)){
                $this->success('注册成功！', '/Qiantai/login2');
            }
            else{
                $this->success('注册失败！', '/Qiantai/register');
            }
        }
        // 写入数据
    }
    /**
     * 简历添加处理
     */
    public function resume_action(){
        $tp=D("resume");
        $Dao = M("resume");	// 实例化模型类
        // 构建写入的数据数组
        $db=$tp->test();
        $data["id"] = $db;
        $data["xingming"] = $_POST['realnameValue'];
        $data["political"] = $_POST['mianmaoValue'];
        $data["birthday"] = $_POST['birthdayValue'];
        $data["phone"] = $_POST['phoneValue'];
        $data["email"] = $_POST['youxiangValue'];
        $data["intention"] = $_POST['yixiangValue'];
        $data["school"] = $_POST['biyeValue'];
        $data["education"] = $_POST['xueliValue'];
        $data["gerenpingjia"] = $_POST['gerenpingjia'];
        // 写入数据
        if($lastInsId = $Dao->add($data)){
            $this->success('添加成功！', '/Qiantai/index');
        } else {
            $this->success('添加失败！', '/Qiantai/resume_add');
        }
    }

    /**
     * 求职者信息显示
     */
    public function index(){
        /** @var jobhunterModel $db */
        $db=D("jobhunter");
//        $username2 = $db->test();
//        $mpg['id']=$username2;
//        $test=$db->where($mpg)->find();
//        $this->assign("user",$test);
//        $test=$db->where($mpg)->find();
//        $this->assign("passwords",$test);
        $db1=$db->test();
        $username = $db->fetch($db1)->username;
        $this->assign("username",$username);
        $passwords = $db->fetch($db1)->passwords;
        $this->assign("passwords",$passwords);
        $this->display('index');
    }

    /**
     * 求职者信息删除显示
     */
    public function jobhunter_delete(){
        $db=D("jobhunter");
        $username = $db->fetch(2)->username;
        $this->assign("username",$username);
        $passwords = $db->fetch(2)->passwords;
        $this->assign("passwords",$passwords);
        $this->display('jobhunter_delete');
    }

    /**
     * 公司信息更改
     */
    public function job_change(){
        $xinxi = D("jobhunter"); // 实例化User对象
        // 更改用户的name和email的值
        $db1=$xinxi->test();
        $data = array('username'=>$_POST['username'],'passwords'=>$_POST['psw']);
        $xinxi-> where($db1)->setField($data);
        if($lastInsId = $xinxi){
            $this->success('更新成功！', '/Qiantai/login2');
        } else {
            $this->error('更新失败！');
        }
    }
    /**
     * 简历信息显示
     */
    public function resume(){
        $db=D("resume");
        $db1=$db->test();
        $xingming = $db->fetch($db1)->xingming;
        $this->assign("xingming",$xingming);
        $political = $db->fetch($db1)->political;
        $this->assign("political",$political);
        $birthday = $db->fetch($db1)->birthday;
        $this->assign("birthday",$birthday);
        $phone = $db->fetch($db1)->phone;
        $this->assign("phone",$phone);
        $email = $db->fetch($db1)->email;
        $this->assign("email",$email);
        $intention = $db->fetch($db1)->intention;
        $this->assign("intention",$intention);
        $school = $db->fetch($db1)->school;
        $this->assign("school",$school);
        $education = $db->fetch($db1)->education;
        $this->assign("education",$education);
        $gerenpingjia = $db->fetch($db1)->gerenpingjia;
        $this->assign("gerenpingjia",$gerenpingjia);
        $this->display('resume');
    }
//    /**
//     * fieldwork2显示
//     */
//    public function fieldwork2(){
//        $db=D("recruit");
//        $db1=$db->test();
//        $id = $db->fetch($db1)->id;
//        $this->assign("id",$id);
//        $occupation = $db->fetch($db1)->occupation;
//        $this->assign("occupation",$occupation);
//        $leibie = $db->fetch($db1)->leibie;
//        $this->assign("leibie",$leibie);
//        $min_money = $db->fetch($db1)->min_money;
//        $this->assign("min_money",$min_money);
//        $max_money = $db->fetch($db1)->max_money;
//        $this->assign("max_money",$max_money);
//        $content1 = $db->fetch($db1)->content1;
//        $this->assign("content1",$content1);
//        $this->display('fieldwork2');
//    }
    /**
     * 简历信息更改
     */
    public function resume_changes(){
        $xinxi = D("resume"); // 实例化User对象
        // 更改用户的name和email的值
        $db1=$xinxi->test();
        $data = array(
            'xingming'=>$_POST['realnameValue'],
            'political'=>$_POST['mianmaoValue'],
            'birthday'=>$_POST['birthdayValue'],
            'phone'=>$_POST['phoneValue'],
            'email'=>$_POST['youxiangValue'],
            'intention'=>$_POST['yixiangValue'],
            'school'=>$_POST['biyeValue'],
            'education'=>$_POST['xueliValue'],
            'gerenpingjia'=>$_POST['gerenpingjia']
        );
        $xinxi-> where($db1)->setField($data);
        if($lastInsId = $xinxi){
            $this->success('更新成功！', '/Qiantai/resume');
        } else {
            $this->error('更新失败！');
        }
    }
    /**
     * 账号信息删除
     */
    public function job_delete(){
        $delete = M("jobhunter"); // 实例化delete对象
        $db1=$delete->test();
        $delete->where($db1)->delete(); // 删除id为2的用户数据
        $this->success('删除成功！', '/Qiantai/login');
    }
    /**
     * 简历信息删除
     */
    public function resume_delete(){
        $delete = M("resume"); // 实例化delete对象
        $db1=$delete->test();
        $delete->where($db1)->delete(); // 删除id为1的用户数据
        $this->success('删除成功！', '/Qiantai/index');
    }
    /**
     * 招聘信息搜索
     */
//    public function search(){
//        $Dao = M("recruit");
//        // 构造查询条件
//        $condition['leibie'] = $_POST['leibie'];
//        // 计算总数
//        $count = $Dao->where($condition)->count();
//        $this->assign("education",$condition['leibie']);
//        $this->assign("gerenpingjia",$count);
       // 导入分页类
//        import("ORG.Util.Page");
        // 实例化分页类
//        $p = new Page($count, 10);
        // 获取查询参数
//        $map['status'] = $_POST['status'];
//        $map['email'] = $_POST['email'];
//        foreach($map as $key=>$val) {
//            $p->parameter .= "$key=".urlencode($val)."&";
//        }
       // 分页显示输出
//        $page = $p->show();
//
        // 当前页数据查询
//        $list = $Dao->where($condition)->order('uid ASC')->limit($p->firstRow.','.$p->listRows)->select();
//
        // 赋值赋值
//        $this->assign('page', $page);
//        $this->assign('list', $list);
//
//        $this->display('fieldwork2');
//    }
/**
 投递跳转
 */
    public function zhaopin()
    {
        $db=D("recruit");
        $db1=$_POST['id'];
        $occupation = $db->fetch($db1)->occupation;
        $this->assign("occupation",$occupation);
        $leibie = $db->fetch($db1)->leibie;
        $this->assign("leibie",$leibie);
        $min_money = $db->fetch($db1)->min_money;
        $this->assign("min_money",$min_money);
        $max_money = $db->fetch($db1)->max_money;
        $this->assign("max_money",$max_money);
        $content1 = $db->fetch($db1)->content1;
        $this->assign("content1",$content1);
        $tp=D("jobhunter");
        $db2=$tp->test();
        $username=$tp->fetch($db2)->username;
        $this->assign("username",$username);
        $this->display('zhaopin');
    }
    /**
     * 投递添加处理
     */
    public function zhaopin_add(){
        $Dao = D("delivery");	// 实例化模型类
        $db1=$Dao->test();
        $gangwei=$_POST;
        // 构建写入的数据数组
        $data["deliver_id"] = $db1;
        $data['jobhunter1']=$gangwei['jianli'];
        $thismonth=date('Y-m-d');
        $data['time']=$thismonth;
        // 写入数据
        $Dao = M("delivery");
        if($lastInsId = $Dao->add($data)){
            $this->success('添加成功！', '/Qiantai/fieldwork2');
        } else {
            $this->success('添加失败！', '/Qiantai/zhaopin');
        }
    }
}

